$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'storeMaterialIn/storematerialin/list',
        datatype: "json",
        colModel: [			
			{ label: 'inId', name: 'inId', index: 'in_id', width: 50, key: true },
			{ label: '单据号', name: 'inNo', index: 'in_no', width: 80 }, 			
			{ label: '含税总金额', name: 'totalMoney', index: 'total_money', width: 80 }, 			
			{ label: '是否含税:1.是,0.否', name: 'tax', index: 'tax', width: 80 }, 			
			{ label: '入库仓库id', name: 'stockId', index: 'stock_id', width: 80 }, 			
			{ label: '库存交易类型：1.采购入库2.红冲3.盘存10.采购退货7.调拨入库8.数据迁移', name: 'type', index: 'type', width: 80 }, 			
			{ label: '库存交易方向(1增加,-1减少)', name: 'direction', index: 'direction', width: 80 }, 			
			{ label: '单据状态：1.待入库审核2.已入库3.已驳回', name: 'status', index: 'status', width: 80 }, 			
			{ label: '备注', name: 'remark', index: 'remark', width: 80 }, 			
			{ label: '创建人', name: 'createName', index: 'create_name', width: 80 }, 			
			{ label: '创建时间', name: 'createTime', index: 'create_time', width: 80 }, 			
			{ label: '审核人', name: 'checkName', index: 'check_name', width: 80 }, 			
			{ label: '审核时间', name: 'checkTime', index: 'check_time', width: 80 }, 			
			{ label: '采购单财务付款状态 notSubmit:待提交 examine：待审核 false:待付款 true：已付款', name: 'paymentStatus', index: 'payment_status', width: 80 }, 			
			{ label: '财务付款时间', name: 'paymentDate', index: 'payment_date', width: 80 }, 			
			{ label: '财务付款备注', name: 'paymentRemark', index: 'payment_remark', width: 80 }, 			
			{ label: '入库单据图片', name: 'purchaseImages', index: 'purchase_images', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		storeMaterialIn: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.storeMaterialIn = {};
		},
		update: function (event) {
			var inId = getSelectedRow();
			if(inId == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(inId)
		},
		saveOrUpdate: function (event) {
			var url = vm.storeMaterialIn.inId == null ? "storeMaterialIn/storematerialin/save" : "storeMaterialIn/storematerialin/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.storeMaterialIn),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var inIds = getSelectedRows();
			if(inIds == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "storeMaterialIn/storematerialin/delete",
                    contentType: "application/json",
				    data: JSON.stringify(inIds),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(inId){
			$.get(baseURL + "storeMaterialIn/storematerialin/info/"+inId, function(r){
                vm.storeMaterialIn = r.storeMaterialIn;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});